package com.ruoyi.project.dentalOrder.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.work.domain.WorkProcessItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.dentalOrder.mapper.DentalOrderMapper;
import com.ruoyi.project.dentalOrder.domain.DentalOrder;
import com.ruoyi.project.dentalOrder.service.IDentalOrderService;

/**
 * 产品订单Service业务层处理
 * 
 * @author wyh
 * @date 2024-08-20
 */
@Service
public class DentalOrderServiceImpl implements IDentalOrderService 
{
    @Autowired
    private DentalOrderMapper dentalOrderMapper;

    /**
     * 查询产品订单
     * 
     * @param outTradeNo 产品订单主键
     * @return 产品订单
     */
    @Override
    public DentalOrder selectDentalOrderByOutTradeNo(String outTradeNo)
    {
        return dentalOrderMapper.selectDentalOrderByOutTradeNo(outTradeNo);
    }

    /**
     * 查询产品订单列表
     * 
     * @param dentalOrder 产品订单
     * @return 产品订单
     */
    @Override
    public List<DentalOrder> selectDentalOrderList(DentalOrder dentalOrder)
    {
        return dentalOrderMapper.selectDentalOrderList(dentalOrder);
    }

    /**
     * 新增产品订单
     * 
     * @param dentalOrder 产品订单
     * @return 结果
     */
    @Override
    public int insertDentalOrder(DentalOrder dentalOrder)
    {
        dentalOrder.setCreateTime(DateUtils.getNowDate());
        return dentalOrderMapper.insertDentalOrder(dentalOrder);
    }

    /**
     * 修改产品订单
     * 
     * @param dentalOrder 产品订单
     * @return 结果
     */
    @Override
    public int updateDentalOrder(DentalOrder dentalOrder)
    {
        dentalOrder.setUpdateTime(DateUtils.getNowDate());
        return dentalOrderMapper.updateDentalOrder(dentalOrder);
    }

    /**
     * 批量删除产品订单
     * 
     * @param outTradeNos 需要删除的产品订单主键
     * @return 结果
     */
    @Override
    public int deleteDentalOrderByOutTradeNos(String[] outTradeNos)
    {
        return dentalOrderMapper.deleteDentalOrderByOutTradeNos(outTradeNos);
    }

    /**
     * 删除产品订单信息
     * 
     * @param outTradeNo 产品订单主键
     * @return 结果
     */
    @Override
    public int deleteDentalOrderByOutTradeNo(String outTradeNo)
    {
        return dentalOrderMapper.deleteDentalOrderByOutTradeNo(outTradeNo);
    }

    @Override
    public List<SysUser> queryWorkers() {
        List<WorkProcessItem> items = dentalOrderMapper.queryAllWorkers();
        List<SysUser> users = new ArrayList<>();
        for(WorkProcessItem item:items){
            //获取部门所有成员
            Long deptId = item.getDeptId();
            List<SysUser> deptUsers = dentalOrderMapper.queryAllDeptWorkers(deptId);
            for (SysUser u:deptUsers){
                users.add(u);
            }
        }
        return users;
    }
}
